﻿using ChainAnalises.Classes.EventTheory;
using ChainAnalises.Classes.IntervalAnalysis;
using ChainAnalises.Classes.Root.SimpleTypes;
using CharacteristicCalculator.Model;
using NUnit.Framework;

namespace TestCharacteristicCalculator.Model
{
    [TestFixture]
    public class TestChainGetter
    {
        [Test]
        public void TestGetNucleotideChain1()
        {
            string Input = "CCGTACTTCGTAGAT";
            Chain Output = ChainGetters.GetNucleotideChain(Input);
            Assert.AreEqual(4, Output.Alpahbet.power);
            Assert.AreEqual("C", Output[0].ToString());
            Assert.AreEqual("A", Output[4].ToString());
            Assert.AreEqual("G", Output[2].ToString());
            Assert.AreEqual("T", Output[3].ToString());
            Assert.AreEqual(15, Output.Length);
        }

        [Test]
        public void TestGetNucleotideChain2()
        {
            string Input = "     CCG\rTACTT\nCG TAGAT";
            Chain Output = ChainGetters.GetNucleotideChain(Input);
            //"CCGTACTTCGTAGAT"
            Assert.AreEqual(4, Output.Alpahbet.power);
            Assert.AreEqual("C", Output[0].ToString());
            Assert.AreEqual("C", Output[1].ToString());
            Assert.AreEqual("G", Output[2].ToString());
            Assert.AreEqual("T", Output[3].ToString());
            Assert.AreEqual("A", Output[4].ToString());
            Assert.AreEqual("C", Output[5].ToString());
            Assert.AreEqual("T", Output[6].ToString());
            Assert.AreEqual("T", Output[7].ToString());
            Assert.AreEqual("C", Output[8].ToString());
            Assert.AreEqual("G", Output[9].ToString());
            Assert.AreEqual("T", Output[10].ToString());
            Assert.AreEqual("A", Output[11].ToString());
            Assert.AreEqual("G", Output[12].ToString());
            Assert.AreEqual("A", Output[13].ToString());
            Assert.AreEqual("T", Output[14].ToString());
            Assert.AreEqual(15, Output.Length);
        }

        [Test]
        public void TestGetAminoChain1()
        {
            string Input = "CCGTACTTCGTAGAT";
            Chain Output = ChainGetters.GetAminoChain(ChainGetters.GetNucleotideChain(Input));
            Assert.AreEqual(5, Output.Alpahbet.power);
            Assert.AreEqual("Pro", Output[0].ToString());
            Assert.AreEqual("Tyr", Output[1].ToString());
            Assert.AreEqual("Phe", Output[2].ToString());
            Assert.AreEqual("Val", Output[3].ToString());
            Assert.AreEqual("Asp", Output[4].ToString());
            Assert.AreEqual(5, Output.Length);
        }

        [Test]
        public void TestGetAminoChain2()
        {
            string Input = "     CCG\rTACTT\nCGTAGAT\n";
            Chain Output = ChainGetters.GetAminoChain(ChainGetters.GetNucleotideChain(Input));
            Assert.AreEqual(5, Output.Alpahbet.power);
            Assert.AreEqual("Pro", Output[0].ToString());
            Assert.AreEqual("Tyr", Output[1].ToString());
            Assert.AreEqual("Phe", Output[2].ToString());
            Assert.AreEqual("Val", Output[3].ToString());
            Assert.AreEqual("Asp", Output[4].ToString());
            Assert.AreEqual(5, Output.Length);
        }

        [Test]
        public void TestGetSimpleNucleotideChain()
        {
            string Input = "CCGTACTTCGTAGAT";
            ValueChar Char1 = new ValueChar('C');
            ValueChar Char2 = new ValueChar('G');
            ValueChar Char3 = new ValueChar('T');
            ValueChar Char4 = new ValueChar('A');
            UniformChain Output1 = ChainGetters.GetSimpleNucleotideChain(ChainGetters.GetNucleotideChain(Input), Char1);
            UniformChain Output2 = ChainGetters.GetSimpleNucleotideChain(ChainGetters.GetNucleotideChain(Input), Char2);
            UniformChain Output3 = ChainGetters.GetSimpleNucleotideChain(ChainGetters.GetNucleotideChain(Input), Char3);
            UniformChain Output4 = ChainGetters.GetSimpleNucleotideChain(ChainGetters.GetNucleotideChain(Input), Char4);
            Assert.AreEqual(1, Output1.Alpahbet.power);
            Assert.AreEqual("C", Output1[0].ToString());
            Assert.AreEqual("C", Output1[1].ToString());
            Assert.AreEqual("C", Output1[5].ToString());
            Assert.AreEqual("C", Output1[8].ToString());
            Assert.AreEqual("C", Output1[8].ToString());
            Assert.AreEqual(PsevdoValue.Instance(), Output1[2]);
            Assert.AreEqual(15, Output1.Length);

            Assert.AreEqual(1, Output2.Alpahbet.power);
            Assert.AreEqual("G", Output2[2].ToString());
            Assert.AreEqual("G", Output2[9].ToString());
            Assert.AreEqual("G", Output2[12].ToString());
            Assert.AreEqual(PsevdoValue.Instance(), Output2[0]);
            Assert.AreEqual(15, Output2.Length);

            Assert.AreEqual(1, Output3.Alpahbet.power);
            Assert.AreEqual("T", Output3[3].ToString());
            Assert.AreEqual("T", Output3[6].ToString());
            Assert.AreEqual("T", Output3[7].ToString());
            Assert.AreEqual("T", Output3[10].ToString());
            Assert.AreEqual("T", Output3[14].ToString());
            Assert.AreEqual(PsevdoValue.Instance(), Output3[0]);
            Assert.AreEqual(15, Output3.Length);

            Assert.AreEqual(1, Output4.Alpahbet.power);
            Assert.AreEqual("A", Output4[4].ToString());
            Assert.AreEqual("A", Output4[11].ToString());
            Assert.AreEqual("A", Output4[13].ToString());
            Assert.AreEqual(PsevdoValue.Instance(), Output4[0]);
            Assert.AreEqual(15, Output4.Length);
        }
    }
}
